varying vec3 out_norm;
varying vec3 out_pos;
varying float out_material;

uniform vec3 material_ka[600];
uniform vec3 material_kd[600];
uniform vec3 material_ks[600];

/**
 *  Very simple fragment shader
 */
void main(void)
{
    vec3 dir_light_dir = vec3(-1.0, -1.0, -1.0);
    vec3 dir_light_base_color = material_ka[int(out_material)];

    float shade_level_dir = abs(dot(dir_light_dir, out_norm));
    vec3 shaded_color_dir = dir_light_base_color*shade_level_dir;

    vec3 dir_light_dir2 = vec3(1.0, 1.0, -1.0);
    vec3 dir_light_base_color2 = material_kd[int(out_material)];

    float shade_level_dir2 = cos(1.0 - abs(dot(dir_light_dir2, out_norm)))*1.5;
    vec3 shaded_color_dir2 = dir_light_base_color2*shade_level_dir2*shade_level_dir2*shade_level_dir2;

    vec3 extra_color = material_ks[int(out_material)];

    vec3 shaded_color = shaded_color_dir*0.2
            + shaded_color_dir2*0.3
            + extra_color*0.25;

    gl_FragColor = vec4(shaded_color, 1.0);
}

//void main(void)
//{
//    vec3 dir_light_dir = vec3(-1.0, -1.0, -1.0);
//    vec3 dir_light_base_color = vec3(0.3, 0.3, 0.4);

//    float shade_level_dir = abs(dot(dir_light_dir, out_norm));
//    vec3 shaded_color_dir = dir_light_base_color*shade_level_dir;

//    vec3 dir_light_dir2 = vec3(1.0, 1.0, -1.0);
//    vec3 dir_light_base_color2 = vec3(0.3, 0.3, 0.4);

//    float shade_level_dir2 = cos(1.0 - abs(dot(dir_light_dir2, out_norm)))*1.5;
//    vec3 shaded_color_dir2 = dir_light_base_color2*shade_level_dir2*shade_level_dir2*shade_level_dir2;

//    vec3 extra_color = vec3(0.1, 0.1, 0.1);

//    vec3 shaded_color = shaded_color_dir*1.2
//            + shaded_color_dir2*0.4
//            + extra_color;

//    gl_FragColor = vec4(shaded_color, 1.0);
//    //    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
//}
